home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / os20 / wb / toolmanager2_0.lha / ToolManager / Source / library / soundobj.c < prev    next >
C/C++ Source or Header  |  1992-09-26  |  5KB  |  186 lines

  1. /*
  2.  * soundobj.c  V2.0
  3.  *
  4.  * TMObject, Type: Sound
  5.  *
  6.  * (c) 1990-1992 Stefan Becker
  7.  */
  8.  
  9. #include "ToolManagerLib.h"
  10.  
  11. /* extended TMObject structure for TMOBJTYPE_SOUND objects */
  12. struct TMObjectSound {
  13.                       struct TMObject  so_Object;
  14.                       char            *so_Command;
  15.                       char            *so_Port;
  16.                       char            *so_ARexxCmd;
  17.                       ULONG            so_CmdLen;
  18.                      };
  19.  
  20. /* Create a Sound object */
  21. struct TMObject *CreateTMObjectSound(struct TMHandle *handle, char *name,
  22.                                      struct TagItem *tags)
  23. {
  24.  struct TMObjectSound *tmobj;
  25.  
  26.  /* allocate memory for object */
  27.  if (tmobj=AllocateTMObject(sizeof(struct TMObjectSound))) {
  28.   struct TagItem *ti,*tstate;
  29.  
  30.   /* Set object defaults */
  31.   tmobj->so_Port=DefaultPortName;
  32.   tmobj->so_Command=DefaultNoName;
  33.  
  34.   /* Scan tag list */
  35.   tstate=tags;
  36.   while (ti=NextTagItem(&tstate)) {
  37.  
  38.    DEBUG_PRINTF("Got Tag (0x%08lx)\n",ti->ti_Tag);
  39.  
  40.    switch (ti->ti_Tag) {
  41.     case TMOP_Command: {
  42.                         char *s=(char *) ti->ti_Data;
  43.                         if (s) tmobj->so_Command=s;
  44.                        }
  45.                        break;
  46.     case TMOP_Port:    {
  47.                         char *s=(char *) ti->ti_Data;
  48.                         if (s) tmobj->so_Port=s;
  49.                        }
  50.                        break;
  51.    }
  52.   }
  53.  
  54.   /* Calculate command line length */
  55.   tmobj->so_CmdLen=15+strlen(tmobj->so_Port)+strlen(tmobj->so_Command);
  56.  
  57.   /* Get memory for command line */
  58.   if (tmobj->so_ARexxCmd=AllocMem(tmobj->so_CmdLen+1,MEMF_PUBLIC)) {
  59.    char *cp=tmobj->so_ARexxCmd;
  60.  
  61.    /* Build ARexx command */
  62.    strcpy(cp,"'address \"");
  63.    strcat(cp,tmobj->so_Port);
  64.    strcat(cp,"\" \"");
  65.    strcat(cp,tmobj->so_Command);
  66.    strcat(cp,"\"'");
  67.  
  68.    /* All OK */
  69.    return(tmobj);
  70.   }
  71.   FreeMem(tmobj,sizeof(struct TMObjectSound));
  72.  }
  73.  
  74.  /* call failed */
  75.  return(NULL);
  76. }
  77.  
  78. /* Delete a Sound object */
  79. BOOL DeleteTMObjectSound(struct TMObjectSound *tmobj)
  80. {
  81.  DEBUG_PRINTF("Delete/Sound (0x%08lx)\n",tmobj);
  82.  
  83.  /* Remove links */
  84.  DeleteAllLinksTMObject((struct TMObject *) tmobj);
  85.  
  86.  /* Remove object from list */
  87.  Remove((struct Node *) tmobj);
  88.  
  89.  /* Free resources */
  90.  FreeMem(tmobj->so_ARexxCmd,tmobj->so_CmdLen+1);
  91.  
  92.  /* Free object */
  93.  FreeMem(tmobj,sizeof(struct TMObjectSound));
  94.  
  95.  /* All OK. */
  96.  return(TRUE);
  97. }
  98.  
  99. /* Change a Sound object */
  100. struct TMObject *ChangeTMObjectSound(struct TMHandle *handle,
  101.                                      struct TMObjectSound *tmobj,
  102.                                      struct TagItem *tags)
  103. {
  104.  struct TagItem *ti,*tstate;
  105.  char *oldcmd,*oldport,*oldline;
  106.  ULONG oldlen;
  107.  
  108.  /* Scan tag list */
  109.  tstate=tags;
  110.  while (ti=NextTagItem(&tstate)) {
  111.  
  112.   DEBUG_PRINTF("Got Tag (0x%08lx)\n",ti->ti_Tag);
  113.  
  114.   switch (ti->ti_Tag) {
  115.    case TMOP_Command: {
  116.                        char *s=(char *) ti->ti_Data;
  117.                        oldcmd=tmobj->so_Command;
  118.                        if (s) tmobj->so_Command=s;
  119.                       }
  120.                       break;
  121.    case TMOP_Port:    {
  122.                        char *s=(char *) ti->ti_Data;
  123.                        oldport=tmobj->so_Port;
  124.                        if (s) tmobj->so_Port=s;
  125.                       }
  126.                       break;
  127.   }
  128.  }
  129.  
  130.  /* Get old command line parameters */
  131.  oldline=tmobj->so_ARexxCmd;
  132.  oldlen=tmobj->so_CmdLen;
  133.  
  134.  /* Calculate command line length */
  135.  tmobj->so_CmdLen=15+strlen(tmobj->so_Port)+strlen(tmobj->so_Command);
  136.  
  137.  /* Calculate command line length */
  138.  if (tmobj->so_ARexxCmd=AllocMem(tmobj->so_CmdLen+1,MEMF_PUBLIC)) {
  139.   char *cp=tmobj->so_ARexxCmd;
  140.  
  141.   /* Free old command line */
  142.   FreeMem(oldline,oldlen+1);
  143.  
  144.   /* Build ARexx command */
  145.   strcpy(cp,"'address \"");
  146.   strcat(cp,tmobj->so_Port);
  147.   strcat(cp,"\" \"");
  148.   strcat(cp,tmobj->so_Command);
  149.   strcat(cp,"\"'");
  150.  
  151.   /* All OK */
  152.   return(TRUE);
  153.  }
  154.  
  155.  /* call failed */
  156.  tmobj->so_Command=oldcmd;
  157.  tmobj->so_Port=oldport;
  158.  tmobj->so_ARexxCmd=oldline;
  159.  tmobj->so_CmdLen=oldlen;
  160.  return(FALSE);
  161. }
  162.  
  163. /* Allocate & Initialize a TMLink structure */
  164. struct TMLink *AllocLinkTMObjectSound(struct TMObjectSound *tmobj)
  165. {
  166.  struct TMLink *tml;
  167.  
  168.  /* Allocate memory for link structure */
  169.  if (tml=AllocMem(sizeof(struct TMLink),MEMF_CLEAR|MEMF_PUBLIC))
  170.   /* Initialize link structure */
  171.   tml->tml_Size=sizeof(struct TMLink);
  172.  
  173.  return(tml);
  174. }
  175.  
  176. /* Activate a Sound object */
  177. void ActivateTMObjectSound(struct TMLink *tml)
  178. {
  179.  struct TMObjectSound *tmobj=tml->tml_Linked;
  180.  
  181.  DEBUG_PRINTF("Activate/Sound\n");
  182.  
  183.  /* Send ARexx command */
  184.  SendARexxCommand(tmobj->so_ARexxCmd,tmobj->so_CmdLen);
  185. }
  186.